<html>
<head>
    <meta charset="utf-8">
    <title>转办代理事宜</title>
    <#include "/pubHeadStyleTree.html">
</head>
<body>
    <div style="position: relative;height: 100%;">
        <div class="ccpui-trees" >
            <p class="isShowTree colorSwitch">
                <span style="float: left;color: #fff">&nbsp;&nbsp;流程分类</span>
                <i layadmin-event="treeFlexible" class="layui-icon layui-icon-prev"></i>
            </p>
            <div style="margin-top: 6px;" >
                <ul class="ccpui-iconTree iconTrees">
                    <li><a class="iconfont iconshuaxin- zTree-refresh" title="刷新"></a></li>
                    <li><a class="iconfont iconwenjianjia1-copy zTree-triangle-d" title="展开"></a></li>
                    <li><a class="iconfont iconfolder1 zTree-triangle-r" title="收起"></a></li>
                    <input type="text" style="width: 50%" class="catZtreeValue">
                </ul>
                <ul id="treeSelectGlobalType" class="ztree ccpui-listZtree"></ul>
            </div>
        </div>
        <div class="ccpui-coreContent" style="position: absolute;top:10px;right:10px;bottom: 0;left: 250px">
            <table id="taskExeItem" lay-filter="taskExeItem" ></table>
        </div>
    </div>
    <script type="text/html" id="headerToolsBar">
        <div class="ccpui-enterSel">
        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-sm" lay-event="query">
                <i class="layui-icon layui-icon-search"></i>
                <span>查询</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="reset">
                <i class="layui-icon layui-icon-refresh"></i>
                <span>重置</span>
            </a>
            <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delSome">
                <i class="layui-icon layui-icon-delete"></i>
                <span>批量取消</span>
            </a>
        </div>

        <form class="layui-form" action="" lay-filter="searchForm" style="margin-top:10px">
            <div class="table-top-filter bpmTaskExeLable">
                <div class="table-filter-alone">
                    <label class="layui-form-label">请求标题</label>
                    <input type="text" name="Q_subject_SL" id="subject" class="layui-input filter-value"
                           placeholder="请求标题"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">流程名称</label>
                    <input type="text" name="Q_processName_SL" id="processName" class="layui-input filter-value"
                           placeholder="流程名称"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">转办（代理）人</label>
                    <input type="text" name="Q_assigneeName_SL" id="assigneeName" class="layui-input filter-value" placeholder="转办（代理）人" />
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">创建人</label>
                    <input type="text" name="Q_creator_SL" id="creator" class="layui-input filter-value"
                           placeholder="创建人" />
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">创建时间</label>
                    <input type="text" name="Q_createTime_DL" id="createTime" class="layui-input filter-value"
                           placeholder="开始时间"/>
                    <span style="float:left;margin-left:46px">至</span>
                    <input type="text" name="Q_endCreateTime_DG" id="endCreateTime" class="layui-input filter-value"
                           placeholder="结束时间"
                           style="margin-left:60px"/>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">转办（代理）类型</label>
                    <select name="Q_status_S" id="status" class="layui-input filter-value">
                        <option value="">所有</option>
                        <option value="0">初始状态</option>
                        <option value="1">完成任务</option>
                        <option value="2">取消转办（代理）</option>
                        <option value="3">其他</option>
                    </select>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">当前状态</label>
                    <select name="Q_assignType_S" id="assignType" class="layui-input filter-value">
                        <option value="">所有</option>
                        <option value="1">代理</option>
                        <option value="2">转办</option>
                        <option value="4">多级转办</option>
                    </select>

                </div>
            </div>
        </form>
        </div>
    </script>
    <script type="text/html" id="managerBar">
        {{# if(d.status == 0){ }}
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="cancel">取消</a>
        {{# }else{ }}
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        {{# } }}
        {{# if(d.assignType == 2 || d.assignType == 4){ }}
        <a class="layui-btn layui-btn-xs" lay-event="detail">转办明细</a>
        {{# } }}
    </script>
    <script>
        layui.config({
            base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['index','table', 'layer', 'util', 'commons', 'setter', 'totalFilter', 'common', 'laydate','admin'], function () {
            var table = layui.table;
            var layer = layui.layer;
            var util = layui.util;
            var $ = layui.$;
            var laydate = layui.laydate;
            var setter = layui.setter;
            var commons = layui.commons;
            var common = layui.common;
            var totalFilter = layui.totalFilter;
            var admin = layui.admin;

            var tableH = commons.tabHeight();

            catZtree();
            loadTable(serverPath.workflowPath + setter.workflowLinkPath + 'bpmTaskExe/taskExeList');

            function catZtree() {
                $.ajax({
                    url: serverPath.workflowPath + setter.workflowLinkPath+"processRun/getAlreadyMatterAndCompletedMattersType?category=" + 'assignMatters',
                    type: "post",
                    dataType: 'json',
                    async: false,
                    success: function (data) {
                        var zNodes = data.data;
                        var setting = {
                            view: {
                                showLine: false,
                                nameIsHTML: true, //允许name支持html
                                selectedMulti: false
                            },
                            edit: {
                                enable: false,
                                editNameSelectAll: false
                            },
                            data: {
                                simpleData: {
                                    enable: true,
                                    idKey: "typeId",
                                    pIdKey: "parentId"

                                },
                                key: {
                                    name: "typeName"
                                }
                            },

                            callback: {
                                onClick: onClickType
                            }
                        };
                        $.fn.zTree.init($('#treeSelectGlobalType'), setting, zNodes);
                        component.fuzzySearch('treeSelectGlobalType', '.catZtreeValue', null, true); //初始化模糊搜索方法
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.alert("暂无数据，请稍后操作！" + XMLHttpRequest.status);
                    }
                });
            }

            //点击流程类型
            function onClickType(event, treeId, treeNode) {
                var selectTypeId = treeNode.typeId;
                var nodePath = treeNode.nodePath;
                var url = serverPath.workflowPath + setter.workflowLinkPath + 'bpmTaskExe/taskExeList?typeId=' + selectTypeId + '&nodePath=' + nodePath;
                if (null == treeNode.parentId) {
                    url = serverPath.workflowPath + setter.workflowLinkPath + 'bpmTaskExe/taskExeList';
                }
                loadTable(url);
                commons.reflashDate({startName: '#createTime', endName: '#endCreateTime'});
            }

            //展开
            $(".iconTrees .zTree-triangle-d").click(function () {
                $.fn.zTree.getZTreeObj("treeSelectGlobalType").expandAll(true);
            });
            //收起
            $(".iconTrees .zTree-triangle-r").click(function () {
                $.fn.zTree.getZTreeObj("treeSelectGlobalType").expandAll(false);
            });
            //刷新
            $(".iconTrees .zTree-refresh").click(function () {
                catZtree();
            });

            //列表数据装载
            function loadTable(url) {
                table.render({
                    elem: '#taskExeItem'
                    , cellMinWidth: 80
                    , title: '流程实例列表'
                    , height: tableH
                    , url: url
                    , method: 'post'
                    , toolbar: '#headerToolsBar'
                    ,defaultToolbar: ['filter', 'print']
                    , autoSort: false
                    , page: true
                    , cols: [[
                        {type: 'checkbox', fixed: 'left'}
                        , {
                            field: 'subject',
                            title: '请求标题',
                            sort: true,
                            align: 'center',
                            event: 'processDetail',
                            minWidth: 330,
                            style: 'color:#1E9FFF;cursor:pointer'
                        }
                        , {field: 'processName', title: '流程名称', sort: true, align: 'center'}
                        , {
                            field: 'creator',
                            title: '创建人',
                            sort: true,
                            align: 'center',
                            event: 'creator',
                            style: 'color:#1E9FFF;cursor:pointer'
                        }
                        , {
                            field: 'assigneeName',
                            title: '转办（代理）人',
                            sort: true,
                            align: 'center',
                            event: 'assigneeName',
                            style: 'color:#1E9FFF;cursor:pointer'
                        }
                        , {
                            field: 'createTime', title: '创建时间', sort: true, align: 'center', templet: function (d) {
                                if (d.createTime == undefined) {
                                    return "";
                                } else {
                                    return util.toDateString(d.createTime, "yyyy-MM-dd");
                                }
                            }
                        }
                        , {
                            field: 'status', title: '转办(代理)类型', sort: true, align: 'center', templet: function (d) {
                                if (d.status == undefined) {
                                    return "";
                                }
                                if (d.status == 0) {
                                    return '<span style="color: #15cc08;">初始状态</span>';
                                }
                                if (d.status == 1) {
                                    return '<span style="color: #15cc08;">完成任务</span>';
                                }
                                if (d.status == 2) {
                                    if (d.assignType == 1) {
                                        return '<span style="color: #cc0c00;">取消代理</span>';
                                    } else {
                                        return '<span style="color: #cc0c00;">取消转办</span>';
                                    }
                                }
                                if (d.status == 3) {
                                    return '<span style="color: #15cc08;">其他</span>';
                                }
                                return "";
                            }
                        }
                        , {
                            field: 'assignType', title: '代办类型', sort: true, align: 'center', templet: function (d) {
                                if (d.assignType == undefined) {
                                    return "";
                                }
                                if (d.assignType == 1) {
                                    return '<span style="color: #15cc08;">代理</span>';
                                }
                                if (d.assignType == 2) {
                                    return '<span style="color: #15cc08;">转办</span>';
                                }
                                if (d.assignType == 3) {
                                    return '<span style="color: #15cc08;">流转</span>';
                                }
                                if (d.assignType == 4 ) {
                                    return '<span style="color: #15cc08;">多级转办</span>';
                                }
                            }
                        }
                        , {title: '管理', toolbar: '#managerBar', width: 150, align: 'center'}
                    ]]
                    , done: function (res) {
                        commons.reflashDate({startName: '#createTime', endName: '#endCreateTime'});
                        common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel')
                        //status!=0时，无法被选中
                        var dataArr = res.data;
                        if(dataArr!=null) {
                            for (var i = 0; i < dataArr.length; i++) {
                                if (dataArr[i]["status"] != 0) {
                                    $("tr[data-index=" + dataArr[i]['LAY_TABLE_INDEX'] + "] input[type='checkbox']").prop("disabled", true);
                                }
                            }
                        }
                    }
                });
                totalFilter.init('taskExeItem');
            }
            //刷新事件
            function reload(){
                table.reload('taskExeItem', {
                    page: {
                        curr: 1
                    }
                });
                totalFilter.init('taskExeItem');
            }
            //辅助按钮监听事件
            table.on('toolbar(taskExeItem)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                var data = checkStatus.data; //获取选中行数据
                switch (obj.event) {
                    case 'query':
                        common.tableConditionRender("taskExeItem", "searchForm", {where: {}}, false);
                        break;
                    case 'reset':
                        common.tableConditionRender("taskExeItem", "searchForm", {where: {}}, true);
                        break;
                    case 'delSome':
                        if (data.length === 0) {
                            layer.msg('请选择记录！',{icon:5});
                        } else {
                            var seleIds = [];
                            for (var i = 0; i < data.length; i++) {
                                if(data[i].status==0) {
                                    seleIds.push(data[i].id);
                                }
                            }
                            var s = seleIds.toString();
                            var body;
                            var iframeWin;
                            layer.open({
                                type: 2,
                                title: "批量取消转办",
                                area: ['550px', '320px'],
                                btn:['确定','关闭'],
                                content:serverPath.workflowPath  + setter.workflowLinkPath + 'bpmTaskExe/view/delBatch?ids=' + s
                                ,success: function(layero, index){
                                    body = layer.getChildFrame('body', index);
                                    iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                                }
                                ,yes:function (index,layero) {
                                    //执行iframe页的save方法
                                    iframeWin.save(index,reload);
                                }
                            });
                        }
                        break;
                }
            });
            //监听行工具事件
            table.on('tool(taskExeItem)', function (obj) {
                var iframeWin;
                var data = obj.data;
                var runId = data.runId;
                switch (obj.event) {
                    //取消
                    case 'cancel':
                        layer.open({
                            type: 2,
                            title: "取消转办（代理）",
                            shade: 0.3,
                            area: ['550px', '310px'],
                            btn:['确定','关闭'],
                            content:serverPath.workflowPath  + setter.workflowLinkPath + 'bpmTaskExe/view/delBatchOnlyOne?id=' + data.id
                            ,success: function(layero, index){
                                iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                            }
                            ,yes:function (index,layero) {
                                //执行iframe页的save方法
                                iframeWin.dataFormSave(index,reload);
                            }
                        });
                        break;
                    //删除
                    case 'del':
                        layer.confirm('确定删除当前数据吗？',{skin: 'btn-class'}, function () {
                            $.ajax({
                                url: serverPath.workflowPath + setter.workflowLinkPath + 'bpmTaskExe/del',
                                type:'post',
                                dataType: 'json',
                                data: {id:data.id},
                                success: function (data) {
                                    //提示消息
                                    layer.msg(data.msg, {time: 2500, icon:6});
                                    //执行重载
                                    reload();
                                }
                            })
                        });
                        break;
                    //转办明细
                    case 'detail':
                        layer.open({
                            type: 2,
                            area: ['550px','420px'],
                            content: serverPath.workflowPath  + setter.workflowLinkPath + 'bpmTaskExe/view/get?id=' + data.id
                        });
                        break;
                    //请求标题
                    case 'processDetail':
                        layer.open({
                            type: 2,
                            title: "流程明细",
                            shade: 0.3,
                            left: 200,
                            area: ['80%', '80%'],
                            content: serverPath.workflowPath  + setter.workflowLinkPath + 'processRun/view/info?runId=' + runId

                        });
                        break;
                    //创建人
                    case 'creator':
                        layer.open({
                            type: 2,
                            area: ['1000px', '620px'],
                            title: ['用户信息'],
                            content:serverPath.systemPath + setter.sysLinkPath +'sysUser/view/view?userId=' + data.creatorId
                        });
                        break;
                    //转办（代理）人
                    case 'assigneeName':
                        layer.open({
                            type: 2,
                            area: ['1000px', '620px'],
                            title: ['用户信息'],
                            content:serverPath.systemPath + setter.sysLinkPath +'sysUser/view/view?userId=' + data.assigneeId
                        });
                        break;
                }
            });
            commons.reflashDate({startName: '#createTime', endName: '#endCreateTime'});
            window.Initialization = function () {
                commons.reflashDate({startName: '#createTime', endName: '#endCreateTime'});
            };
            common.tableSort("taskExeItem",{show:window.Initialization});

        })
    </script>
    <style>
        .bpmTaskExeLable .table-filter-alone .layui-form-label{
            width: 142px;
        }
        .layui-table-view .layui-form-checkbox[lay-skin=primary] i{
            margin-top: 4px;
        }
    </style>
</body>
</html>